<?php
class Util_Date
{
    /**
     * Constructor of class
     */
    public function  __construct()
    {
        
    }
    /**
     * Date time diff
     */
    public static function dateTimeDiff($time)
    {
        return self::autoTime($time, time());
    }

    /**
     * Auto time
     */
    public static function autoTime($start_date, $end_date)
    {
        $startDate  = strtotime(date('Y-m-d', $start_date));
        $endDate    = strtotime(date('Y-m-d', $end_date));
        $totalDay   = ($endDate-$startDate)/86400;
        $totalDay   = ($totalDay>=0)?$totalDay:10;
        $arrDay     = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
        $arrDayShow = array('mon'=>'Thứ hai', 'tue'=>'Thứ ba', 'wed'=>'Thứ tư', 'thu'=>'Thứ năm', 'fri'=>'Thứ sáu', 'sat'=>'Thứ bảy', 'sun'=>'Chủ nhật');

        if ( $totalDay == 0 )
        {
            return 'lúc '.date('H:i', $start_date);
        } elseif ( $totalDay == 1 )
        {
            return 'Hôm qua lúc '.date('H:i', $start_date);
        } elseif ( $totalDay>=2 && $totalDay<=6 )
        {
            $date   = strtolower(date('D', $end_date));
            $pos    = array_search($date, $arrDay);
            if ( $totalDay <= $pos )
            {
                $dateShow   = strtolower(date('D', $start_date));
                return $arrDayShow["$dateShow"].' lúc '.date('H:i', $start_date);
            } else
            {
                return date('d/m', $start_date).' lúc '.date('H:i', $start_date);
            }//end if
        } elseif ( date('Y', $start_date) == date('Y', $start_date) )
        {
            return date('d/m', $start_date).' lúc '.date('H:i', $start_date);
        } else
        {
            return date('d/m/Y', $start_date).' lúc '.date('H:i', $start_date);
        }//end if
    }

    /**
     * Check schedule
     */
    public static function checkSchedule($hour, $minute, $second, $day, $month, $year)
    {
        $nextDay    = mktime($hour, $minute, $second, $month, $day, $year);
        $now        = time();
        return $now<$nextDay;
    }
}